/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.c0910g.DAO;

import com.myapp.c0910g.entity.PaymentType;
import com.myapp.c0910g.entity.PaymentTypeFacade;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author BachLe
 */
public class PaymentTypeDAO {
    PaymentTypeFacade paymentTypeFacade = lookupPaymentTypeFacadeBean();

    private PaymentTypeFacade lookupPaymentTypeFacadeBean() {
        try {
            Context c = new InitialContext();
            return (PaymentTypeFacade) c.lookup("java:global/RadioCabsProject/RadioCabsProject-ejb/PaymentTypeFacade!com.myapp.c0910g.entity.PaymentTypeFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<PaymentType> getPayTypes(String payType){
        return paymentTypeFacade.getPaymentTypes(payType);
    }

    public List<PaymentType> showPayType(){
        return paymentTypeFacade.findAll();
    }

     public void addPaymentType(PaymentType typePay){
       paymentTypeFacade.create(typePay);
    }

    public void editPaymentType(PaymentType typePay){
       paymentTypeFacade.edit(typePay);
    }

    public void deletePaymentType(PaymentType typePay){
       paymentTypeFacade.remove(typePay);
    }

    public PaymentType findPaymentTypeById(int id){
        return paymentTypeFacade.find(id);
    }
}
